<template>
  <div class="app-container">
    <div class="left-box" :style="{ height: tableHeight + 104 + 'px' }">
      <xh-area @select="handleNodeClick"></xh-area>
    </div>
    <div class="right-box">
      <xh-list-head
        @on-search="HandleChange"
        ref="TableHead"
        crmType="watch"
        :fielname="fielname"
        :listHander="listHander"
        :pictureExport="true"
      >
        <div class="u-box">
          <span>职务：</span>
          <el-select v-model="job" placeholder="请选择">
            <el-option
              v-for="item in jobOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </xh-list-head>
      <el-table
        v-loading="listLoading"
        :data="tableData"
        element-loading-text="加载中"
        :height="tableHeight"
        use-virtual
        stripe
        border
        highlight-current-row
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          show-overflow-tooltip
          type="selection"
          align="center"
          width="55"
        />
        <el-table-column label="ID" align="center" fixed="left">
          <template slot-scope="scope">
            {{ scope.row.dutyid }}
          </template>
        </el-table-column>
        <el-table-column label="任务名称" align="center" fixed="left">
          <template slot-scope="scope">
            {{ scope.row.dutyname }}
          </template>
        </el-table-column>
        <el-table-column label="任务类型" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.dutytypename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          class-name="status-col"
          label="任务状态"
          min-width="140"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.dutystatus | statusFilter">{{
              scope.row.dutystatus | formatStatus
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="区域" align="center">
          <template slot-scope="scope">
            {{ scope.row.zonename }}
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center">
          <template slot-scope="scope">
            {{ scope.row.createname }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.createt }}
          </template>
        </el-table-column>
        <el-table-column label="执行人" align="center">
          <template slot-scope="scope">
            {{ scope.row.executename }}
          </template>
        </el-table-column>
        <el-table-column label="执行时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.executet }}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center">
          <template slot-scope="scope">
            {{ scope.row.remark }}
          </template>
        </el-table-column>

        <el-table-column label="操作" width="130" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
              class="xm-btn--primary"
              type="primary"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="p-contianer">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size.sync="pageSize"
          :total="total"
          :pager-count="5"
          class="p-bar"
          background
          layout="prev, pager, next, sizes, total, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <!-- 详情 -->
    <xh-watch-detail
      :visible.sync="showDView"
      :id="dutyId"
      @close="showDView = false"
    />
  </div>
</template>

<script>
import XhListHead from "@/components/XhListHead/index.vue";
import XhWatchDetail from "./Detail.vue";
import { getWatchListAPI } from "@/api/watch";
import TableMixin from "../mixins/Table";
import XhArea from "@/components/XhArea";

export default {
  mixins: [TableMixin],

  components: {
    XhListHead,
    XhWatchDetail,
    XhArea,
  },
  data() {
    return {
      list: null,
      listLoading: true,

      //详情
      showDView: false,
      dutyId: "",

      // 筛选
      /**职务 */
      job: "全部",
      jobOptions: [
        {
          label: "全部",
          value: "全部",
        },
        {
          label: "专职以上",
          value: "专职以上",
        },
        {
          label: "作业长",
          value: "作业长",
        },
        {
          label: "班组长",
          value: "班组长",
        },
        {
          label: "员工",
          value: "员工",
        },
      ],

      //导出
      fielname: "作业观察",
      listHander: {
        dutyname: "任务名称",
        dutytypename: "任务类型",
        dutystatus: "任务状态",
        zonename: "区域",
        createname: "创建人",
        createt: "创建时间",
        executename: "执行人",
        executet: "执行时间",
        remark: "备注",
      },
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.search = {
        job: this.job,
        ...this.$refs.TableHead.formatSearch(),
      };
      this.getList(this.search);
    });
  },
  methods: {
    /** tableData */
    getList(search) {
      this.listLoading = true;
      getWatchListAPI({
        pagenum: this.currentPage - 1,
        pagesize: this.pageSize,
        dutytypeid: "dtp2",
        ...search,
      }).then((res) => {
        this.tableData = res.Data;
        this.total = res.Total;
        this.listLoading = false;
      });
    },

    /**职务 */
    HandleChange() {
      const params = {
        job: this.job,
        ...this.$refs.TableHead.formatSearch(),
      };
      this.handleSearch(params);
    },

    /**查看*/
    handleEdit(index, row) {
      this.showDView = true;
      this.dutyId = row.dutyid;
    },
    //tree
    handleNodeClick(data) {
      if (data.Zoneid) {
        this.search.zoneid = data.Zoneid;
      } else {
        delete this.search.zoneid;
      }

      this.getList(this.search);
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left-box {
    width: 260px;
    height: 100%;
    background: #ffffff;
    margin-right: 10px;
  }
  .right-box {
    width: calc(100% - 260px);
  }

  .u-box {
    display: flex;
    align-items: center;
    // width: 25%;
    min-width: 10rem;
    span {
      min-width: 55px;
    }
  }
}
</style>
